package com.bingfabao.cecb;

import java.util.Random;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2021/2/25  13:34
 * 描述:
 */

public class MyCycRun implements Runnable {

    private CyclicBarrier cyclicBarrier;

    public MyCycRun(CyclicBarrier cyclicBarrier) {
        this.cyclicBarrier = cyclicBarrier;
    }

    @Override
    public void run() {

        try {
            Thread.sleep(new Random().nextInt(10000));

            System.out.println(Thread.currentThread().getName()+"=========到达起跑线");

            cyclicBarrier.await();

            System.out.println(Thread.currentThread().getName()+"================起跑");

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }


    }
}
